package com.gukun.springboot.tdengine.controller;

import com.gukun.springboot.tdengine.domain.common.CommonResult;
import com.gukun.springboot.tdengine.domain.select.SelectTask;
import com.gukun.springboot.tdengine.service.select.SelectTaskService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 4998
 * @createDate: 2025-06-11  16:36
 * @description:
 */
@RequestMapping("/api/tdengine/selectTask")
@RestController
public class SelectTaskController {
    @Autowired
    private SelectTaskService selectTaskService;

    @GetMapping("/start")
    public CommonResult<Boolean> start(@RequestParam String id) {
        return CommonResult.success(selectTaskService.start(id));
    }

    @GetMapping("/startByGroupId")
    public CommonResult<Boolean> startByGroupId(@RequestParam int groupId) {
        return CommonResult.success(selectTaskService.startByGroupId(groupId));
    }

    @GetMapping("/startAll")
    public CommonResult<Boolean> startAll() {
        return CommonResult.success(selectTaskService.startAll());
    }

    @GetMapping("/stop")
    public CommonResult<Boolean> stop(@RequestParam String id) {
        return CommonResult.success(selectTaskService.stop(id));
    }

    @GetMapping("/stopByGroupId")
    public CommonResult<Boolean> stopByGroupId(@RequestParam int groupId) {
        return CommonResult.success(selectTaskService.stopByGroupId(groupId));
    }

    @GetMapping("/stopAll")
    public CommonResult<Boolean> stopAll() {
        return CommonResult.success(selectTaskService.stopAll());
    }

    @PostMapping("/saveOrUpdate")
    public CommonResult<Boolean> saveOrUpdate(@RequestBody SelectTask selectTask) throws Exception {
        return CommonResult.success(selectTaskService.saveOrUpdate(selectTask));
    }

    @GetMapping("/delete")
    public CommonResult<Boolean> delete(@RequestParam String id) {
        return CommonResult.success(selectTaskService.delete(id));
    }

    @PostMapping("/list")
    public CommonResult<List<SelectTask>> list(@RequestBody SelectTask selectTask){
        return CommonResult.success(selectTaskService.list(selectTask));
    }
}
